package action;

import dao.LendRecordDAO;
import dao.UserDAO;
import model.LendRecordModel;
import model.UserModel;
import util.WebSiteUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 后台管理员相关操作action类
 */
public class ManagerAction extends BaseAction {

    private List<UserModel> userlist; //用户集合
    private List<LendRecordModel> lendlist; //借书记录集合
    private UserModel um=new UserModel();

    private String userId;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public List<LendRecordModel> getLendlist() {
        return lendlist;
    }

    public void setLendlist(List<LendRecordModel> lendlist) {
        this.lendlist = lendlist;
    }

    public List<UserModel> getUserlist() {
        return userlist;
    }

    public void setUserlist(List<UserModel> userlist) {
        this.userlist = userlist;
    }
    

    public UserModel getUm() {
		return um;
	}

	public void setUm(UserModel um) {
		this.um = um;
	}

	/**
     * 后台管理员查询用户信息
     * @return
     */
    public String userlist(){
        UserDAO dao = new UserDAO();
        //如果用户userId传入则按userId查询，否则查询所有用户
        if(WebSiteUtil.isNotEmpty(this.getUserId())){
            UserModel um = dao.getUserByUserId(this.getUserId());
            if(um!=null){
                this.userlist = new ArrayList<UserModel>();
                this.userlist.add(um);
            }
        }else{
            this.userlist = dao.findAllUser();
        }
        return "userlist";
    }

    /**
     * 后台管理员查看用户借书信息
     * @return
     */
    public String lendlist(){
        LendRecordDAO dao = new LendRecordDAO();
        this.lendlist = dao.findLendRecordByUserId(this.getUserId());
        return "lendlist";
    }
    
    /* 新增用户
    public String adduser(){
    	UserDAO dao =new UserDAO();
    	if(dao.createUser(this.getUm())){
            addActionMessage("新增用户成功！");
        }else{
            addActionMessage("新增用户失败！");
        }
		return "addu";
    	
    }*/
}
